package com.springboot2.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot2.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookServiceTestCase2 {

    @Autowired
    private  IBookService bookService;

    @Test
    void  testGetById(){
        System.out.println(bookService.getById(5));
    }
    //     保存 增
    @Test
    void testSave() {
        Book book = new Book();
        System.out.println("测试数据123");
        book.setType("测试数据123");
        book.setName("测试数据123");
        book.setDescription("测试数据123");
        bookService.save(book);
    }

    //    删
    @Test
    void testDelete() {
        bookService.removeById(9);
        System.out.println("删除成功");
    }
    //    改
    @Test
    void testUpdate() {

        Book book = new Book();
        System.out.println("测试数据888");
        book.setId(8);
        book.setType("测试数88");
        book.setName("测试数据8");
        book.setDescription("88888888");
        bookService.updateById(book);
    }


    //    查询全部


    @Test
    void getAll() {
        bookService.list();
    }
    @Test
    void testGetPage() {
        //        需要添加 mp 拦截器才能分页
        IPage<Book> page = new Page<Book>(2,5);
        bookService.page(page,null);
        System.out.println(page.getCurrent());
        System.out.println(page.getSize());
        System.out.println(page.getTotal());
        System.out.println(page.getPages());
        System.out.println(page.getRecords());
    }


}
